import axios from '@/api'
import { IGrain } from '@/common/services/famer'
import { IProject } from '@/common/services/user'
import { IBasic } from './common'

export interface ISubsidy extends IGrain, ISubsidyBase {
  is_used: string
  member_id: string
  member_nam: string
  member_addr: string
}

export interface ISubsidyBase {
  s_a_id: string
  s_a_nam: string
}

export interface IStatistics extends ISubsidyBase {
  used: string
  member_total: string
}

export interface IGetSubsidyList {
  request: {
    s_a_id?: string
    switch?: string
    bk_price?: string
    commit_id?: string
  }
  response: Array<ISubsidy | IStatistics>
}

export interface IGetSubsidyStandard {
  response: {
    task_id: string
    task_nam: string
    task_doc: string
    s_a_nams: string
    pay_info: ISubsidyStandard[]
  }
}
export interface ISubsidyStandard {
  s_a_id: string
  s_a_nam: string
  pay_unit: string
  pay_price: string
}

export interface IBankReceiptBasic {
  bk_give_id: string
  pay_id: string
  bk_id: string
  bk_order_id: string
  bk_pay_price: string
  bk_pay_time: string
  bk_usr: string
  bk_code: string
  bk_name: string
  bk_time: string
}
export interface IBankReceipt extends IBankReceiptBasic {
  bk_pay_id: string
  s_a_id: string
  op_info: string
  bk_id_name: string
}

export interface IPayee {
  bk_bid: string
  bk_user: string
  bk_nam: string
  bk_num: string
}

export interface IGetBankReceipts {
  request: IBasic & Api.PageOptions
  response: IBankReceipt[]
}

class PayRecordServices {
  constructor() {}

  /**
   * 获取当前行政地区下去补贴农户/大户信息
   *
   * @returns
   * @memberof SubsidyServices
   */
  async getList(data: IGetSubsidyList['request'] & Api.PageOptions) {
    return axios.post<
      unknown,
      Api.ResponseListOptions<IGetSubsidyList['response']>
    >('/btbusiness/pay-log/get-pay-list', data)
  }

  /**
   * 获取当前行政区下导出execl数据
   *
   * @param {IGetSubsidyList['request']} data
   * @returns
   * @memberof PayServices
   */
  async getExportList(data: IGetSubsidyList['request']) {
    return axios.post<
      unknown,
      Api.ResponseListOptions<IGetSubsidyList['response']>
    >('/btbusiness/pay-log/export-pay-list', data, {
      customHandler: true,
      responseType: 'blob',
    })
  }

  /**
   * 查询收款人修改记录
   *
   * @param {Pick<ISubsidy, 'member_id'>} data
   * @returns
   * @memberof PayServices
   */
  getPayeeUpdateLogs(data: Pick<ISubsidy, 'member_id'>) {
    return axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/pay-log/get-pay-info-log',
      data
    )
  }

  /**
   * 获取批次号列表
   *
   * @param {{ s_a_id: string }} data
   * @returns
   * @memberof PayRecordServices
   */
  getCommitLog(data: { s_a_id: string }) {
    return axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/pay-log/get-commit-log',
      data
    )
  }

  /**
   * 查看回单列表V2
   *
   * @param {{ s_a_id: string }} data
   * @returns
   * @memberof PayRecordServices
   */
  getPayBatchList(data: { s_a_id: string }) {
    return axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/pay-log/get-pay-batch-list',
      data
    )
  }

  /**
   * 获取当前行政地区下去补贴农户/大户信息
   *
   * @returns
   * @memberof SubsidyServices
   */
  async getPayV2List(data: IGetSubsidyList['request'] & Api.PageOptions) {
    return axios.post<
      unknown,
      Api.ResponseListOptions<IGetSubsidyList['response']>
    >('/btbusiness/pay-log/get-pay-log-list', data)
  }

  /**
   * 获取当前行政区下导出execl数据
   *
   * @param {IGetSubsidyList['request']} data
   * @returns
   * @memberof PayServices
   */
  async getExportV2List(data: IGetSubsidyList['request']) {
    return axios.post<
      unknown,
      Api.ResponseListOptions<IGetSubsidyList['response']>
    >('/btbusiness/pay-log/batch-export-pay-log-list', data, {
      customHandler: true,
      responseType: 'blob',
    })
  }

  importExeclV2(data: unknown) {
    return axios.post<
      unknown,
      Api.ResponseListOptions
    >('/btbusiness/pay-log/batch-insert-pay-log-list', data, {
      customHandler: true,
    })
  }

  delete(data: { pay_batch_id: string; s_a_id: string }) {
    return axios.post<
      unknown,
      Api.ResponseListOptions
    >('/btbusiness/pay-log/batch-remove-pay-log', data, {
      customHandler: true,
    })
  }
}

export const payRecordServices = new PayRecordServices()

export default PayRecordServices
